#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include <QList>
#include <QPoint>
#include <QPair>


class QTcpServer;
class QTcpSocket;

class Server : public QObject
{
    Q_OBJECT
public:
    explicit Server(QObject *parent = 0);
    
	void init(int port = 55555, QString rootIP = QString("127.0.0.1"), int rootPort = 55555);
	int listenPort();

signals:
	void paint(int mode, QPoint point);
	void appStateNeeded(QTcpSocket *);
	void lockState(int);
    
public slots:
	void serverConnected();
	void socketDisconnected();
	void readyToRead();
	void sendPaintMessage(int mode, QPoint point, QTcpSocket *excluded = 0);
	void onStartupScene(QTcpSocket *socket, QList<QPair<int, QPoint> > list);
	void sendLockMessage(bool lock, QTcpSocket *excluded = 0);
	void sendLock(QTcpSocket *socket, bool lock);


private:
	void sendPaint(QTcpSocket *socket, int mode, QPoint point);

private:
	QTcpServer *server;
	QTcpSocket *root;
	QList<QTcpSocket *> connections;
	quint16 tcpBlockSize;
};

#endif // SERVER_H
